package com.smzd.core.business;

import com.smzd.core.dao.IDao;
import com.smzd.core.domain.IntIdEntity;
import com.smzd.core.utils.db.Page;

public abstract class AbstractService<E extends IntIdEntity> implements
		IService<E> {

	protected abstract IDao<E> getDao();
	
	@Override
	public void insert(E elem) {
		getDao().insert(elem);
	}

	@Override
	public void update(E elem) {
		getDao().update(elem);
	}

	@Override
	public void remove(E elem) {
		getDao().remove(elem);
	}

	@Override
	public E getItemById(int id) {
		return getDao().getElemById(id);
	}

	@Override
	public Page<E> getElemsByPage(Page<E> page) {
		getDao().getElemsByPage(page);
		return page;
	}

	@Override
	public Page<E> getAllElems(Page<E> page) {
		getDao().getAllElems(page);
		return page;
	}
	
	public static Object[] getObjectByField(IntIdEntity field){
		Object[] value = null;
		if(field!=null){
			value = new Object[]{field.getId(), field.getName()};
		}
		return value;
	}
}
